package com.blank;

import com.blank.pojo.bo.User;
import com.blank.service.Impl.UserServiceImpl;
import com.blank.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @author BLANK
 * @date 2020/11/16
 */
@WebServlet("/RegisterServlet")
public class RegisterServlet extends HttpServlet {
   private UserService userService = new UserServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username=request.getParameter("username");
        String password =request.getParameter("password");
        User user =new User();
        user.setUsername(username);
        user.setPassword(password);
        try {
            if (userService.addUser(user)){
                response.getWriter().write("success");
            }else {
                response.getWriter().write("fail");
            }

        } catch (SQLException throwable) {
            throwable.printStackTrace();
        }
    }


}
